﻿using ChronoScript_Compiler.Language;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChronoScript_Compiler.CodeGen
{
    public partial class CodeGen
    {
        public void CompileLine(LanguageDefinition.SyntaxNode sn)
        {
            if (sn is LanguageDefinition.FunctionCall)
            {
                LanguageDefinition.FunctionCall fc = sn as LanguageDefinition.FunctionCall;
                Call(fc);
            }
            else if (sn is LanguageDefinition.Declaration)
            {
                LanguageDefinition.Declaration decl = sn as LanguageDefinition.Declaration;
                DeclareVarAndAssign(decl);
            }
            else if (sn is LanguageDefinition.IfStatement)
            {
                ParseIf(sn as LanguageDefinition.IfStatement);
            }
            else if (sn is LanguageDefinition.WhileStatement)
            {
                ParseWhile(sn as LanguageDefinition.WhileStatement);
            }
            else if (sn is LanguageDefinition.Assignment)
            {
                LanguageDefinition.Assignment asn = sn as LanguageDefinition.Assignment;
                Assign(asn.Name, asn.Value);
            }
            else if (sn is LanguageDefinition.InlineIL)
            {
                LanguageDefinition.InlineIL il = sn as LanguageDefinition.InlineIL;
                foreach (SymbolTable.Scope sc in Symbols.scopes)
                {
                    foreach (Variable v in sc.variables)
                    {
                        il.IL_Code = il.IL_Code.Replace("%" + v.Name, v.RealName);
                    }
                }
                MainClass.Complile(il.IL_Code, ref Assembler);
            }
        }
    }
}
